package com.freesky.quartz.task;

import cn.hutool.core.date.DateUtil;
import com.freesky.biz.abchina.service.IXianglanRecordService;
import com.freesky.biz.icbc.mapper.LotteryMapper;
import com.freesky.biz.icbc.service.ILotteryService;
import com.freesky.biz.icbc.service.IWomenDayService;
import com.freesky.common.core.redis.RedisCache;
import com.freesky.framework.web.service.SendAlarmService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

/**
 * 工行爱购集福气
 */
@Component("happyIotTask")
public class HappyIotTask {
    private static final Logger logger = LoggerFactory.getLogger(HappyIotTask.class);

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private ILotteryService lotteryService;

    @Autowired
    private LotteryMapper lotteryMapper;

    @Autowired
    private IWomenDayService womenDayService;

    @Autowired
    private IXianglanRecordService xianglanRecordService;

    @Autowired
    private SendAlarmService sendAlarmService;

    //private final String LOTTERY_ID = "1016";
    //private final String LOTTERY_HAPPY_IOT_KEY = "LOTTERY_PRIZE:" + LOTTERY_ID ;

    //1 0 0 * * ?
    public void taskProcess() {
        logger.info("HappyIotTask task start");

        Calendar calendar = Calendar.getInstance();
        int dayWeek = calendar.get(Calendar.DAY_OF_WEEK);
        int nDays = Integer.parseInt(DateUtil.format(new Date(),"dd"));
        int nYears = Integer.parseInt(DateUtil.format(new Date(),"yyyy"));
        int nMonth = Integer.parseInt(DateUtil.format(new Date(),"MM"));
        String LOTTERY_ID = "";
        String LOTTERY_PRIZE_KEY = "";

        //顺序：工行爱购周周惠
        String curDate = DateUtil.format(new Date(),"yyyyMMdd");

//        if("20240903".equalsIgnoreCase(curDate)){
//            LotteryPrizeModel lotteryPrizeModel = new LotteryPrizeModel();
//            LotteryItemModel lotteryItemModel = new LotteryItemModel();
//            lotteryPrizeModel.setId(6801);
//            lotteryPrizeModel.setTotalStock(30);
//            lotteryPrizeModel.setValidStock(30);
//            lotteryMapper.updatePrizeById(lotteryPrizeModel);
//
//            lotteryPrizeModel.setId(6802);
//            lotteryPrizeModel.setTotalStock(60);
//            lotteryPrizeModel.setValidStock(60);
//            lotteryMapper.updatePrizeById(lotteryPrizeModel);
//
//            lotteryPrizeModel.setId(6803);
//            lotteryPrizeModel.setTotalStock(2140);
//            lotteryPrizeModel.setValidStock(2140);
//            lotteryMapper.updatePrizeById(lotteryPrizeModel);
//
//            lotteryPrizeModel.setId(6804);
//            lotteryPrizeModel.setTotalStock(1000);
//            lotteryPrizeModel.setValidStock(1000);
//            lotteryMapper.updatePrizeById(lotteryPrizeModel);
//
//            lotteryPrizeModel.setId(6805);
//            lotteryPrizeModel.setTotalStock(0);
//            lotteryPrizeModel.setValidStock(0);
//            lotteryMapper.updatePrizeById(lotteryPrizeModel);
//
//            lotteryPrizeModel.setId(6806);
//            lotteryPrizeModel.setTotalStock(6770);
//            lotteryPrizeModel.setValidStock(6770);
//            lotteryMapper.updatePrizeById(lotteryPrizeModel);
//
//            lotteryItemModel.setId(5801);
//            lotteryItemModel.setPercent(new BigDecimal(0.003));
//            lotteryMapper.updateItemById(lotteryItemModel);
//            lotteryItemModel.setId(5802);
//            lotteryItemModel.setPercent(new BigDecimal(0.006));
//            lotteryMapper.updateItemById(lotteryItemModel);
//            lotteryItemModel.setId(5803);
//            lotteryItemModel.setPercent(new BigDecimal(0.214));
//            lotteryMapper.updateItemById(lotteryItemModel);
//            lotteryItemModel.setId(5804);
//            lotteryItemModel.setPercent(new BigDecimal(0.1));
//            lotteryMapper.updateItemById(lotteryItemModel);
//            lotteryItemModel.setId(5805);
//            lotteryItemModel.setPercent(new BigDecimal(0));
//            lotteryMapper.updateItemById(lotteryItemModel);
//            lotteryItemModel.setId(5806);
//            lotteryItemModel.setPercent(new BigDecimal(0.677));
//            lotteryMapper.updateItemById(lotteryItemModel);
//        }
//        if("20241101".equalsIgnoreCase(curDate)){
//            LotteryPrizeModel lotteryPrizeModel = new LotteryPrizeModel();
//            LotteryItemModel lotteryItemModel = new LotteryItemModel();
//            lotteryPrizeModel.setId(6801);
//            lotteryPrizeModel.setTotalStock(20);
//            lotteryPrizeModel.setValidStock(20);
//            lotteryMapper.updatePrizeById(lotteryPrizeModel);
//
//            lotteryPrizeModel.setId(6802);
//            lotteryPrizeModel.setTotalStock(30);
//            lotteryPrizeModel.setValidStock(30);
//            lotteryMapper.updatePrizeById(lotteryPrizeModel);
//
//            lotteryPrizeModel.setId(6803);
//            lotteryPrizeModel.setTotalStock(2055);
//            lotteryPrizeModel.setValidStock(2055);
//            lotteryMapper.updatePrizeById(lotteryPrizeModel);
//
//            lotteryPrizeModel.setId(6804);
//            lotteryPrizeModel.setTotalStock(905);
//            lotteryPrizeModel.setValidStock(905);
//            lotteryMapper.updatePrizeById(lotteryPrizeModel);
//
//            lotteryPrizeModel.setId(6805);
//            lotteryPrizeModel.setTotalStock(0);
//            lotteryPrizeModel.setValidStock(0);
//            lotteryMapper.updatePrizeById(lotteryPrizeModel);
//
//            lotteryPrizeModel.setId(6806);
//            lotteryPrizeModel.setTotalStock(6990);
//            lotteryPrizeModel.setValidStock(6990);
//            lotteryMapper.updatePrizeById(lotteryPrizeModel);
//
//            lotteryItemModel.setId(5801);
//            lotteryItemModel.setPercent(new BigDecimal(0.002));
//            lotteryMapper.updateItemById(lotteryItemModel);
//            lotteryItemModel.setId(5802);
//            lotteryItemModel.setPercent(new BigDecimal(0.003));
//            lotteryMapper.updateItemById(lotteryItemModel);
//            lotteryItemModel.setId(5803);
//            lotteryItemModel.setPercent(new BigDecimal(0.206));
//            lotteryMapper.updateItemById(lotteryItemModel);
//            lotteryItemModel.setId(5804);
//            lotteryItemModel.setPercent(new BigDecimal(0.091));
//            lotteryMapper.updateItemById(lotteryItemModel);
//            lotteryItemModel.setId(5805);
//            lotteryItemModel.setPercent(new BigDecimal(0));
//            lotteryMapper.updateItemById(lotteryItemModel);
//            lotteryItemModel.setId(5806);
//            lotteryItemModel.setPercent(new BigDecimal(0.699));
//            lotteryMapper.updateItemById(lotteryItemModel);
//        }
//
//        //莆田社保卡，每周一复位
//        if((dayWeek == Calendar.MONDAY) && (nYears==2024)) {
//            LOTTERY_ID = "1007";
//            LOTTERY_PRIZE_KEY = "LOTTERY_PRIZE:" + LOTTERY_ID;
//            lotteryService.resetLotteryById(LOTTERY_ID);
//            redisCache.deleteObject(LOTTERY_PRIZE_KEY);
//
//            //每周一10点到晚上23:59:59
//            LOTTERY_ID = "1029";
//            LOTTERY_PRIZE_KEY = "LOTTERY_PRIZE:" + LOTTERY_ID;
//
//            LotteryModel lotteryModel = new LotteryModel();
//            lotteryModel.setId(LOTTERY_ID);
//            lotteryModel.setStartTime(DateUtil.format(new Date(),"yyyy-MM-dd") +" 10:00:00");
//            lotteryModel.setEndTime(DateUtil.format(new Date(),"yyyy-MM-dd") +" 23:59:59");
//            lotteryMapper.updateLotterById(lotteryModel);
//
//            lotteryService.resetLotteryById(LOTTERY_ID);
//            redisCache.deleteObject(LOTTERY_PRIZE_KEY);
//        }
//
//        //月月超金喜，每周三复位
//        if((dayWeek == Calendar.MONDAY) && (nYears==2024)) {
//            LOTTERY_ID = "1019";
//            LOTTERY_PRIZE_KEY = "LOTTERY_PRIZE:" + LOTTERY_ID;
//            lotteryService.resetLotteryById(LOTTERY_ID);
//            redisCache.deleteObject(LOTTERY_PRIZE_KEY);
//        }
//
//        //每月一号复位
//        if((nDays==1) && (nYears==2024)) {
//            LOTTERY_ID = "1021";
//            LOTTERY_PRIZE_KEY = "LOTTERY_PRIZE:" + LOTTERY_ID;
//            lotteryService.resetLotteryById(LOTTERY_ID);
//            redisCache.deleteObject(LOTTERY_PRIZE_KEY);
//        }
//
//        lotteryService.lotteryInit();
//        if((nMonth==3) && (nDays>=8) && (nDays<=10)){
//            womenDayService.womenDayInit();
//        }

        if((nMonth>=7) && (nYears == 2024)) {
            xianglanRecordService.xianglanRecordInit();
        }

    }


}
